#ifndef ONELINERWIDGET_H
#define ONELINERWIDGET_H

/**
Nectarine Utility Project is a software interface for the web system 'demovibes'
Copyright (C) 2010  Alexandre LAURENT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

website: http://code.google.com/p/nectarine-utility-project/
e-mail: lw.demoscene@gmail.com
**/

#include <QWidget>
#include <QList>
#include <QMap>
#include <QString>

#include "../Types/user.h"
#include "../Types/message.h"

class QGridLayout;
class QHBoxLayout;
class QVBoxLayout;
class QGroupBox;
class QFrame;
class QListWidget;
class QLabel;
class QWebView;
class QLineEdit;
class QUrl;

class QSignalMapper;
class QMenu;
class QAction;
class QListWidgetItem;

class QShowEvent;

class OnelinerViewer;
class OnelinerToolBox;

class OnelinerWidget : public QWidget
{
    Q_OBJECT

private:

    QHBoxLayout* pMainHGrid;
    QGridLayout* pUsersGrid;
    QVBoxLayout* pOnelinerGrid;


    QLabel* pUsersOnlineLabel;
    QListWidget* pUserListWidget;

    OnelinerViewer* pOnelinerViewer;
    OnelinerToolBox* pOnelinerToolBox;
    QLineEdit* pInput;

    // Data
    QList<OMessage> onelinerData;
    QList<QString> parsedOnelinerData;
    QList<User> userOnlineData;
    int nbNewMessages;

    // Parser lists
    QMap<QString, QString> smileyKeywords;
    QList<QString> colourTags;

    // Menu for the user
    QSignalMapper* pUserNameSignalMapper;
    QSignalMapper* pRequesUserPageSignalMapper;
    QSignalMapper* pUserPMSignalMapper;
    QSignalMapper* pUserProfileSignalMapper;
    QAction* pUserNameAction;
    QAction* pRequestUserPageAction;
    QAction* pUserPMAction;
    QAction* pUserProfileAction;
    QMenu* pUserMenu;

    bool isConnected;


    void initParser(void);
    void parseOnelinerMessages(void);
    void parseBBCode(QString& message)const;
    void parseSmileys(QString& message)const;
    void updateWebView(void);

    void addUserColourTag(const QColor& c);

protected:

    void showEvent(QShowEvent* pSE);

protected slots:
    void validateMessage();

    void needOpenLink(const QUrl& url);

    void openUserMenu(QListWidgetItem* pLWI);

    void addNameInMessage(const QString& userName);
    void goToUserPageViewer(const QString& userName);
    void openPMPage(const QString& userName);
    void openProfilePage(const QString& userName);

    void addBold(void);
    void addItalic(void);
    void addUnderlined(void);
    void addStriked(void);

    // Colours
    void addTag(const QString& tag);
    void addUserColour(QColor colour);
    void addSong(unsigned int id);
    void addArtist(unsigned int id);
    void addUser(QString name);
    void addGroup(unsigned int id);
    void addCompilation(unsigned int id);
    void addForum(unsigned int id);
    void addThread(unsigned int id);
    void addFlag(QString flag);

signals:
    void needSendMessage(QString message);
    void needRequestUserPage(QString username);

public:

    OnelinerWidget(QWidget* parent = 0);
    ~OnelinerWidget(void);

    void setUserList(const QList<User>& userOnline);
    void setMessagesData(const QList<OMessage>& messages);

    QString getOnelinerData(void);

    const OnelinerViewer* getOnelinerViewer(void) const { return pOnelinerViewer; }

    void setConnection(const bool enabled);
};

#endif // ONELINERWIDGET_H
